using System;
using System.Collections.Generic;
using Android.Views;

namespace Granite.Axml
{
	public enum BindingMode
	{
		TwoWay,
		OneWay,
		//OneTime,
		//OneWayToSource
	}

	public abstract class BindingBase
	{
		readonly View m_Target;
		
		/// <summary>
		/// Initializes a new instance of the BindingBase class.
		/// </summary>
		/// <param name="rootBindingFragment"></param>
		public BindingBase(View target, BindingFragment rootBindingFragment)
		{
			m_Target = target;
			m_RootBindingFragment = rootBindingFragment;
			m_RootBindingFragment.ValueChanged += (e, s) => OnValueChanged(m_RootBindingFragment.ReadValue());
		}

		/// <summary>
		/// This is invoked when the source property is changed.
		/// </summary>
		/// <param name="value"></param>
		protected abstract void OnValueChanged(object value);

		readonly BindingFragment m_RootBindingFragment;

		public void Activate()
		{
			m_RootBindingFragment.Activate();
			OnValueChanged(m_RootBindingFragment.ReadValue());
		}

		public void Deactivate()
		{
			m_RootBindingFragment.Deactivate();
		}

		protected void WriteValue(object value)
		{
			m_RootBindingFragment.WriteValue(value);
		}

		public View Target
		{
			get { return m_Target; }
		}

	}
}
